

import java.util.Arrays;
import java.util.Scanner;

public class Test6 {
    //二维数组
    public static void main(String[]args) {
        int a = 0;
        int c = 10;
        int []ay2=new int[3];
        ay2[0]=100;
        ay2[1]=200;
        ay2[2]=300;
        System.out.println("a==" + a + c);//拼接a c的值，除非打括号否则视为拼接
        System.out.println("===二维数组的定义===");
        int[][] array = {{1, 2, 3}, {4, 5, 6}};
        int[][] array2 = new int[][]{{1, 2, 3}, {4, 5, 6}};
        int[][] array3 = new int[2][3];
        int[][] arry4 = new int[2][];
        System.out.println("===二维数组的访问===");
        System.out.println("二维数组的行数为" + array2.length);
        System.out.println("二维数组的列数为" + array2[0].length);
        System.out.println("二维数组的列数为" + array2[1].length);
        System.out.println("二维数组的元素为：");
        for (int i = 0; i < array2.length; i++) {
            for (int j = 0; j < array2[0].length; j++) {

                System.out.print(array2[i][j] + " ");
            }
            System.out.println("");
        }
        System.out.println("二维数组的元素为：");
        for (int[] tp : array2) {
            for (int n : tp) {
                System.out.print(n + " ");
            }
            System.out.println();
        }
        System.out.println("二维数组的元素为：");
        System.out.print(Arrays.toString(array2[0]));
        System.out.println();
        System.out.print(Arrays.toString(array2[1]));
        System.out.println();
        System.out.println("二维数组的元素为：");
        String ret = Arrays.deepToString(array2);//深度遍历
        System.out.print(ret);
        //比较数组是否相等（内元素相同）
        int[][] array4 = {{1, 2, 3}, {7, 8, 9}};
        System.out.println();
        System.out.println(array4==array2);
        boolean flag=Arrays.equals(array4,array2);//比较两个数组是否相等的方法
        System.out.println(flag);
        System.out.println("填充数组");
        int [] ay=new int[8];
        Arrays.fill(ay,1);//用1填充数组（Array的填充方法，可选定方法，注意范围为左闭右开）
        System.out.print(ay);//打印出的是地址
        System.out.println();
        System.out.print(Arrays.toString(ay));
        System.out.println();
        Arrays.fill(ay,1,3,-1);//在ay数组中把下标从1到3之间的数填充为-1，注意范围为左闭右开
        System.out.print(Arrays.toString(ay));
        System.out.println();
        //拷贝数组三种方法
        int[][]copy=Arrays.copyOf(array2,array2.length);//拷贝数组的方法，还可以指定拷贝长度
        System.out.print(Arrays.deepToString(copy));
        System.out.println();
        int[][]copy2=Arrays.copyOfRange(array2,0,2);//源数组名，拷贝下标范围，左闭右开,一维数组是从起始下标到末标，二维数组是拷贝起始行到结束行
        System.out.print(Arrays.deepToString(copy2));
        System.out.println();
        int [][]copy3=new int[2][];
        System.arraycopy(array2,1,copy3,0,array2.length-1);//拷贝第三种为本地方法，其参数为源数组，拷贝起始下标/行，拷贝目标数组，拷贝长度/拷贝行数
        System.out.print(Arrays.deepToString(copy3));
        System.out.println();
        //用方法快速排序
        int []array6={2,3,1,6,4};
        System.out.print("排序前的数组"+Arrays.toString(array6));
        Arrays.sort(array6);//排序一维数组
        System.out.print("排序后的数组"+Arrays.toString(array6));
        System.out.println();
        //查找方法
        int index=Arrays.binarySearch(array6,0,5,3);//一维数组查找数的方法，参数为要查找数组名，起始下标，末下标，要查找的数，返回值为找到数的下标
        System.out.println("找到了下标为"+index);
        System.out.println();
        //三个数比大小
        System.out.println("输入要比较的三个数：");
        Scanner in=new Scanner(System.in);
        int k=in.nextInt();
        int j=in.nextInt();
        int m=in.nextInt();
        max1(k,j,m);
    }
    //求最大值
    public static int max1(int a,int b){
        return a>b?a:b;
    }
    public static void max1(int k,int j,int m){
        int max=max1(k,j);
        int ret =max1(max,m);
        System.out.println("k,j,m这三个最大值为"+ret);
    }
}
